import { createApp, Directive, DirectiveBinding } from 'vue';
import App from './App.vue';
import router from '@/router';

import { createPinia } from 'pinia';

import ElementPlus from 'element-plus';
import 'element-plus/theme-chalk/index.css';
import NoneShow from '@/components/NoneShow/index.vue';
import Pagination from '@/components/Pagination/index.vue';
import TreeSelect from '@/components/TreeSelect/index.vue';
import '@/permission';

// 引入svg注册脚本
import 'virtual:svg-icons-register';

import SvgIcon from "@/components/SvgIcon/index.vue";
// element-plus图标
import elementIcons from "@/components/SvgIcon/svgicon";

// 自定义样式
import '@/styles/index.scss';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
const app = createApp(App);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component);
}

app.component("svg-icon", SvgIcon);

const debounce: Directive = {
  mounted(el: any, binding: DirectiveBinding) {
    el.addEventListener('click', e => {
      el.classList.add('is-disabled');
      el.disabled = true;
      setTimeout(() => {
        el.disabled = false;
        el.classList.remove('is-disabled');
      }, 2000); //我这里设置的是2000毫秒也就是2秒
    });
  }
};
// 注册全局组件
app
  .component('NoneShow', NoneShow)
  .component('Pagination', Pagination)
  .component('TreeSelect', TreeSelect)
  .use(createPinia())
  .use(router)
  .use(ElementPlus)
  .use(elementIcons)
  .directive('debounce', debounce)
  .mount('#app');
